package com.mingweicai.intergration.thread.orderprint;

public class Print2 implements Runnable{

  public static volatile int flag = -1;

  int start ;
  int n;
  int cFlag ;
  int nFlag ;

  public Print2(int start, int n, int cFlag, int nFlag) {
    this.start = start;
    this.n = n;
    this.cFlag = cFlag;
    this.nFlag = nFlag;
  }

  @Override
  public void run() {
    for(int i=start; i<=n; i+=3){
      while(flag != cFlag) continue;
      System.out.println(i);
      flag = nFlag;
    }
  }

  public static void main(String args[]){
    new Thread(new Print2(1,100, -1, 1 )).start();
    new Thread(new Print2(2,100, 1, 2 )).start();
    new Thread(new Print2(3,100, 2, -1)).start();
  }

}
